<?php 
class chat_mod extends CI_Model{
	public function __construct()
	{
		parent::__construct();
		
		$this->load->database();
		$this->load->library('session');
	}
	//查询聊天
	public function chat($uid='')
	{
		$query=$this->db->query("select username, color, msg, HOUR(sent_on) AS hour, MINUTE(sent_on) AS minutes, SECOND(sent_on) AS seconds from msg where uid='".$uid."' order by sent_on desc limit 5");
		//$query=$this->db->query("select username, color, msg, HOUR(sent_on) AS hour, MINUTE(sent_on) AS minutes, SECOND(sent_on) AS seconds from msg AS m left join msg_data AS md ON m.uid=md.uid where md.uid='".$uid."' order by sent_on asc limit 5");
		return $query->result_array();
	}
	
	//查询个人聊天
	public function get_msg($uid='')
	{
		$query=$this->db->query("select * from msg AS m left join msg_data AS md ON m.uid=md.uid where md.uid='".$uid."'");
		return $query->result_array();
	}
	
	//插入个人聊天
	public function add_msg($uid,$msg_user,$msg,$username)
	{
		//echo "insert into msg(uid,username,msg) values('".$uid."','".$username."','".$msg."')";
		$query=$this->db->query("insert into msg(uid,username,msg) values('".$uid."','".$username."','".$msg."')");
		$query=$this->db->query("insert into msg(uid,username,msg) values('".$msg_user."','".$username."','".$msg."')");
	}
	
}
?>